package Review;

public class Test18 {

	public static void main(String[] args) {

	}
	public static boolean hasSubtree(BinaryTreeNode root1,BinaryTreeNode root2){
		if(root1==null){
			return false;
		}
		if(root2==null){
			return true;
		}
		boolean result = false;
		if(root1.value==root2.value){
			result = doesTree1HasTree2(root1,root2);
		}
		if(!result){
			result=hasSubtree(root1.left, root2);
		}
		if(!result){
			result=hasSubtree(root1.right, root2);
		}
		return result;
	}
	public static boolean doesTree1HasTree2(BinaryTreeNode root1,BinaryTreeNode root2){
		if(root1==null){
			return false;
		}
		if(root2==null){
			return true;
		}
		if(root1.value!=root2.value){
			return false;
		}
		return doesTree1HasTree2(root1.left, root2.left)&&doesTree1HasTree2(root1.right, root2.right);
			
	}

}
